import 'package:flutter/material.dart';

class CheckBoxPage extends StatefulWidget {
  CheckBoxPage({Key key}) : super(key: key);

  @override
  _CheckBoxPageState createState() => _CheckBoxPageState();
}

class _CheckBoxPageState extends State<CheckBoxPage> {
  var flag = true;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("CheckBox页面"),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Checkbox(
                value: this.flag,
                onChanged: (selectStatus) {
                  setState(() {
                    this.flag = selectStatus;
                    print(this.flag);
                  });
                },
                activeColor: Colors.orange,
              )
            ],
          ),
          SizedBox(height: 20),
          Row(
            children: <Widget>[Text(this.flag ? "选中" : "未选中")],
          ),
          CheckboxListTile(
            value: this.flag,
            onChanged: (selectStatus) {
              setState(() {
                this.flag = selectStatus;
              });
            },
            title: Text("标题"),
            subtitle: Text("二级标题"),
          ),
          Divider(),
          CheckboxListTile(
            value: this.flag,
            onChanged: (selectStatus) {
              setState(() {
                this.flag = selectStatus;
              });
            },
            title: Text("标题"),
            subtitle: Text("二级标题"),
            secondary: Icon(Icons.select_all),
          )
        ],
      ),
    );
  }
}
